﻿#include<iostream>
using namespace std;
int main() {
	int* p;
	int* t;
	{
		int* a = new int[50];
		a[2] = 255;
		t = a;
		delete[] a;

		unique_ptr<int[]>b{ make_unique<int[]>(50) };
		b[2] = 250;
		p = b.get();
		cout << p[2] << endl;//250
	}
	cout << t[2] << endl;//255
	cout << p[2] << endl;//-572662307，说明内存空间已经被释放

	int* e;
	shared_ptr<int> c{  };
	{
		int* r = new int[5];
		e = r;
		r[0] = 1;
		delete[] r;

		shared_ptr<int> s{ make_shared<int>(5) };
		c = s;
		cout << *s << endl;//5
	}
	cout << *e << endl;//-572662307，说明内存空间已经被释放了，如果是想继续用该指针，可以用共享指针
	cout << *c << endl;//5，指针成功被保留
}
//